<?php

class Antz_Form_Components_BankNumber extends Antz_Form_Component
{
     public function __construct($name, $label, $value=array(), $id=''){
         if(count($value)==0){
             $value = array('bank'=>'', 'branch'=>'', 'account'=>'', 'suffix'=>'');
         };
         if($id=='') $id = 'bank'.rand();
         $this->id = $id;
         $this->val = $value['account'];
         $this->name = $name;
         $this->label = $label;
         $this->bank = Antz::newObject('Antz_Form_Components_Input', array('text', $name.'Bank', '', $value['bank']));
         $this->bank->showLabel(false);
         $this->bank->setWrap(false);
         $this->bank->addClass('extraShort marginRightMin');
         $this->branch = Antz::newObject('Antz_Form_Components_Input', array('text', $name.'Branch', '', $value['branch']));
         $this->branch->showLabel(false);
         $this->branch->setWrap(false);
         $this->branch->addClass('short marginRightMin');
         $this->account = Antz::newObject('Antz_Form_Components_Input', array('text', $name.'Account', '', $value['account']));
         $this->account->showLabel(false);
         $this->account->setWrap(false);
         $this->account->addClass('med marginRightMin');
         $this->suffix = Antz::newObject('Antz_Form_Components_Input', array('text', $name.'Suffix', '', $value['suffix']));
         $this->suffix->showLabel(false);
         $this->suffix->setWrap(false);
         $this->suffix->addClass('extraShort marginRightMin');
     }

     public static function getNumberFromForm($name){
         $bank = post($name.'Bank');
         $branch = post($name.'Branch');
         $acct = post($name.'Account');
         $suff = post($name.'Suffix');
         return trim($bank.' '.$branch.' '.$acct.' '.$suff);
     }

     public function render(){
     	global $gCms;
     	$Antz = Antz::registry('Antz');
     	 if($this->required) $this->aftertext = '<span class="required"><img src="'.$gCms->config['root_url'].'/modules/Antz/images/required.gif" alt="'.$Antz->Lang('required').'" /></span>'.$this->aftertext;
         $returnString = $this->bank->render().$this->branch->render().$this->account->render().$this->suffix->render();
         if($this->showLabel) $returnString = '<label for="'.$this->getId().'">'.$this->label.'</label>'.$returnString;
         if($this->wrap) $returnString = $this->wrap($returnString);
         return $returnString;
     }

}
